//
//  HotViewController.m
//  Koala_Fm
//
//  Created by dllo on 16/3/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotViewController.h"
#import "AFNetBlock.h"
#import "HotTableViewCell.h"
#import "HotModel.h"
#import <UIImageView+WebCache.h>
@interface HotViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation HotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"热门榜单";
    
    /** tableView 设置**/
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
//    self.tableView.backgroundColor = [UIColor cyanColor];
    [self.view addSubview: _tableView];
    [_tableView release];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    // 重用池
    [_tableView registerClass:[HotTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    /** 数据获取 **/
    NSString *strVC = @"http://api.kaolafm.com/api/v4/top/list?pagesize=1&pagenum=20&support=1&installid=0002JX3E&udid=bd80d675b1bb04bd76de2a42a3aca09d&sessionid=bd80d675b1bb04bd76de2a42a3aca09d1452837603979&imsi=460077347218243&operator=0&lon=121.544506&lat=38.883264&network=1&timestamp=1452837644&sign=ad0e64ef4e4695f26aab782327753a6b&resolution=720*1280&devicetype=0&channel=B-xiaomi&version=4.5.1&appid=0&";
    [AFNetBlock GetDataWithURL:strVC block:^(id block) {
        NSArray *arrVC = block[@"result"][@"dataList"];
        
        self.dataArr = [HotModel modelHandlerWithArray:arrVC];
        // 刷新页面
        
        [_tableView reloadData];
        
        
    }];
}
#pragma mark - tableView的协议设置
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    HotModel *m = _dataArr[indexPath.row];
    [cell.imag sd_setImageWithURL:[NSURL URLWithString:m.img]];
    cell.lableOne.text =[ [_dataArr[indexPath.row]dataList] objectAtIndex:0];
    cell.lableTow.text = [[_dataArr[indexPath.row] dataList] objectAtIndex:1];
    cell.lableThree.text = [[_dataArr[indexPath.row]dataList] objectAtIndex:2];
    return cell;
}
// cell 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 105;
}
// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
